<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<include file="Public/head" />
</head>

<body>
<include file="Public/top" />

<div class="login_tit">用户注册</div>
<div class="page_in margin">
  <form action="" method="post" onSubmit="return check_submit(this)" id="reg_form">
    <div class="ginput_div ginput_div_icon"><i class="icon-shouji1"></i><input class="ginput" type="text" name="mobile" id="mobile" placeholder="手机号" maxlength="11" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-mima"></i><input class="ginput" type="password" name="password" id="password" placeholder="请设置密码" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-mima"></i><input class="ginput" type="password" name="password2" id="password2" placeholder="请确认密码" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-yonghu"></i><input class="ginput" type="text" name="username" id="username" placeholder="账户名" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-qq"></i><input class="ginput" type="text" name="qqnum" id="qqnum" placeholder="QQ" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-mima"></i><input class="ginput" onKeyDown="if(event.keyCode==13){checkSubmit();}" type="text" name="verify_code" id="verify_code" placeholder="请输入验证码" maxlength="4" /><span class="code"><img id="verify_code_img" class="verify_code_img_reg" src="{:U('Mobile/User/verify',array('type'=>'user_reg'))}" onclick="verify('verify_code_img_reg')"  /></span></div>
    <div class="ginput_div ginput_div_icon">
      <div class="fl"><i class="icon-yanzhengma2"></i><input class="ginput" name="code" id="code" type="text" placeholder="短信验证码" /></div>
      <div class="fr"><button type="button" class="reg_send" id="count_down1" onClick="send_sms_reg_code()">获取短信验证码</button></div>
      <div class="clear"></div>
    </div>
    <div class="ginput_div ifaggree_div"><span><input type="checkbox" name="ifaggree" id="ifaggree" /></span> 我同意《 <a href="javascript:void(0)" onclick="reg_xieyi(1)">朋伴网络服务使用协议</a> 》</div>
    <div class="ginput_div"><button type="submit" class="login_sub">同意协议并注册</button></div>
  </form>
</div><!--page_in-->

<script>

    flag = true;
    $(document).ready(function(){
	
        $("input[name='username']").blur(function () {
            var username = $(this).val();
            var re = /^(13[0-9]{9})|(15[^4,\\D][0-9]{8})|(18[0-9]{9})|(17[0-9]{9})|((\w{1,20}@\w{1,20}.[a-z]{2,5}))$/;
            var id = $(this).attr("id");
            if (re.test(username)) {
                $.ajax({
                    type : "GET",
                    url:"/index.php?m=Mobile&c=Api&a=issetMobileOrEmail",//+tab,
                    data :{mobile:username},// 你的formid 搜索表单 序列化提交
                    success: function(data)
                    {
                        if(data != '0')
                        {
                            flag = false;
                        }else{
                            flag = true;
                        }
                    }
                });
            }else{
                flag = false;
            }
        })
    });
	
	function countdown(divid,counttime)
	{
		$(divid).attr("disabled","disabled");
		$(divid).addClass("reg_send_off");
		
		counttime--;
        if(counttime<=-1)
        {
			$(divid).removeAttr("disabled");
			$(divid).removeClass("reg_send_off");
            $(divid).html("获取短信验证码");
            return false;
        }

        $(divid).html(counttime+'秒');

        setTimeout("countdown('"+divid+"',"+counttime+")",1000);
	}
	
    // 发送手机短信
    function send_sms_reg_code(){
        var mobile = $('#mobile').val();
        if(!checkMobile(mobile)){
            // layer.alert('请输入正确的手机号码', {icon: 2});// alert('请输入正确的手机号码');
            layer.alert('请输入正确的手机号码.', 800);
            return;
        }

        var url = "/index.php?m=Mobile&c=User&a=send_sms_reg_code";

		$.ajax({
		  type:"post",
		  url:url,
		  data:{"mobile":mobile},
		  dataType:"json",
		  
		  success:function(data)
		  {

		      if(data.status!=1){
                  layer.alert(data.msg, 800);
                  return false;
              }
			  //发送成功
			  if(data.status=1)
			  {
				  counttime = "{$sms_time_out}"; // 手机短信超时时间
				  countdown('#count_down1',counttime);
			  }
		  }
		});
    }
    function checkMobile(tel) {
        var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
        if (reg.test(tel)) {
            return true;
        }else{
            return false;
        };
    }

	// 普通 图形验证码 
    function verify(id){
        $('.'+id).attr('src','/index.php?m=Mobile&c=User&a=verify&type=user_reg&r='+Math.random());

  /*      var r = Math.random();
        window.location.href="{:U(MODULE_NAME.'/Likecloth/delete/sample_id/"+sampleid+"')}";

        $('.'+id).attr('src',{:U('Mobile/User/verify')});
*/





      // $('#verify_code_img').attr('src','/index.php?m=Mobile&c=User&a=verify&r='+Math.random());
    }
    function check_submit(o)
	{
		if(!o.mobile.value)
		{
			layer.tips('手机号不能为空', '#mobile', {tips: [1, '#f39800']});
			return false;
		}
		if(o.mobile.value.length<11)
		{
			layer.tips('手机最少为11位', '#mobile', {tips: [1, '#f39800']});
			return false;
		}
		if(!o.password.value)
		{
			layer.tips('密码不能为空', '#password', {tips: [1, '#f39800']});
			return false;
		}
		if(o.password.value.length<6)
		{
			layer.tips('密码最少为6位', '#password', {tips: [1, '#f39800']});
			return false;
		}
		if(o.password.value!=o.password2.value)
		{
			layer.tips('两次输入密码不一致', '#password2', {tips: [1, '#f39800']});
			return false;
		}
		if(!o.username.value)
		{
			layer.tips('账户名不能为空', '#username', {tips: [1, '#f39800']});
			return false;
		}
		if(!o.qqnum.value)
		{
			layer.tips('QQ不能为空', '#qqnum', {tips: [1, '#f39800']});
			return false;
		}
		if(!o.verify_code.value)
		{
			layer.tips('验证码不能为空', '#verify_code', {tips: [1, '#f39800']});
			return false;
		}
		if(!o.code.value)
		{
			layer.tips('短信验证码不能为空', '#code', {tips: [1, '#f39800']});
			return false;
		}
		//var ifaggree = document.getElementById("ifaggree");
		if(!o.ifaggree.checked)
		{
			layer.tips('您必须仔细阅读使用协议并同意', '#ifaggree', {tips: [1, '#f39800']});
			return false;
		}
    }
</script>

<script>

    countdown("#count_down1","{$stime}");

</script>

<include file="Public/footer" />
</body>
</html>